﻿using System;
using System.Threading;
using System.Web.Mvc;
using SinBiota.Model.Business.PersistenceServices.Interfaces;
using Sinbiota.Web.ActionFilters;

namespace Sinbiota.Web.Controllers
{
    [HandleError]
    public class HomeController : BaseController
    {
        private readonly IUserPersistenceServices _userPersistenceServices;

        public HomeController(IUserPersistenceServices userPersistenceServices)
        {
            _userPersistenceServices = userPersistenceServices;
        }

        [ImportMessagesFromTempData]
        public ActionResult Index()
        {
            
            return View();
        }

        [ImportMessagesFromTempData]
        public ActionResult About()
        {
            ViewData["Version"] = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            return View(Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "pt" ? "About" : "About-en");
        }

        [ImportMessagesFromTempData]
        public ActionResult EnvironmentalInformations()
        {
            return View();
        }

        
        [ImportMessagesFromTempData]
        [Authorize]
        public ActionResult UserPage()
        {
            var user = _userPersistenceServices.FindByUsername(User.Identity.Name);
            return user == null ? View("NotFound") : View(user);
        }
    }
}
